package com.skyline.jfs.cluster.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.skyline.jfs.cluster.model.JFSNode;

public class JFSNodeMapper implements RowMapper<JFSNode> {
	private static Integer heartbeat = 3 * 60+20 ;
	
	private static JFSNodeMapper mapper = new JFSNodeMapper();

	public static JFSNodeMapper getMapper() {
		return mapper;
	}

	@Override
	public JFSNode mapRow(ResultSet rs, int rowNum) throws SQLException {

		JFSNode j = new JFSNode();
		j.setAdminiJobNum(rs.getLong("administrator"));
		j.setCreatedTime(rs.getTimestamp("createdTime"));
		j.setDescription(rs.getString("description"));
		// j.setExist(exist)
		j.setHeartbeat(rs.getTimestamp("heartbeat"));
		//j.setHeartRate(rs.getInt("heartRate"));
		j.setId(rs.getInt("id"));
		j.setIp(rs.getString("ip"));
		j.setLoadbalancingFactor(rs.getInt("loadbalancingFactor"));
		j.setName(rs.getString("name"));
		j.setStorageDirctory(rs.getString("storageDirctory"));
		j.setUpdateTime(rs.getTimestamp("updateTime"));
		j.setTotalSpace(rs.getLong("totalSpace"));
		j.setUsableSpace(rs.getLong("usableSpace"));
		if(rs.getInt("current_timestamp-heartbeat")<heartbeat){
			j.setActivity("NORMAL");
		}else{
			j.setActivity("ERROR");
		}
		return j;
	}

}